package com.fafa.swing.base;


import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * @author : fafa
 * @version V1.0
 * @Project: SwingTest
 * @Package com.fafa.swing
 * @Description: JSliderDemo
 * @date Date : 2019年11月24日 21:25
 */
public class JSliderDemo extends JFrame {

    public static void main(String[] args) {
        JFrame jFrame = new JFrame("滑块组件示例");
        jFrame.setBounds(500,500,400,200);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container contentPane = jFrame.getContentPane();
        JSlider slider = new JSlider(0,100);
        slider.setMajorTickSpacing(10);
        slider.setMinorTickSpacing(5);
        slider.setPaintLabels(true);
        slider.setPaintTicks(true);

        JLabel label = new JLabel();
        contentPane.add(label, BorderLayout.SOUTH);
        slider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                label.setText("当前数值为:"+slider.getValue());
            }
        });

        contentPane.add(slider);
        jFrame.setVisible(true);
    }
}
